package com.cpp.server.tools;

import com.alibaba.fastjson.JSON;
import com.cpp.common.constant.redis.CsOpRedisConstant;
import com.cpp.pojo.pojo.User;
import com.cpp.server.context.UserHolder;
import groovy.util.logging.Slf4j;
import lombok.RequiredArgsConstructor;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.List;

@lombok.extern.slf4j.Slf4j
@Slf4j
@RequiredArgsConstructor
@Component
public class CourseOptimizationTool {
    private final StringRedisTemplate stringRedisTemplate;

    @Tool(description = "单独保存总体趋势部分")
    public void saveCauses(
            @ToolParam(description = "课程总体趋势列表") List<String> causes) {
        User currentUser = UserHolder.getCurrentUser();
        log.info("已保存趋势分析：{}",  causes);
        stringRedisTemplate.opsForValue().set(CsOpRedisConstant.TENDENCY_KEY + currentUser.getId(), JSON.toJSONString(causes));
    }

    @Tool(description = "单独保存优化建议部分")
    public void saveSuggestions(
            @ToolParam(description = "针对课程的教学优化建议") List<String> suggestions) {
        User currentUser = UserHolder.getCurrentUser();
        log.info("已保存优化建议：{}" , suggestions);
        stringRedisTemplate.opsForValue().set(CsOpRedisConstant.SUGGESTIONS_KEY + currentUser.getId(), JSON.toJSONString(suggestions));
    }

    @Tool(description = "单独保存可执行措施部分")
    public void saveActionItems(
            @ToolParam(description = "具体的可执行改进措施") List<String> actionItems) {
        User currentUser = UserHolder.getCurrentUser();
        log.info("已保存可执行措施：{}" , actionItems);
        stringRedisTemplate.opsForValue().set(CsOpRedisConstant.ACTION_ITEMS_KEY + currentUser.getId(), JSON.toJSONString(actionItems));
    }


}